package com.ambulance.framework.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2的接口配置
 *
 * @author zhao
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {


//    public static final String SWAGGER_SCAN_ADMIN_PACKAGE = "com.ambulance.project.biz.controller.admin";
    public static final String SWAGGER_SCAN_PAD_PACKAGE = "com.ambulance.project.biz.controller.pad";
    public static final String SWAGGER_SCAN_WEB_PACKAGE = "com.ambulance.project.biz.controller.bigweb";
    public static final String SWAGGER_SCAN_VR_PACKAGE = "com.ambulance.project.biz.controller.vr";
    public static final String SWAGGER_SCAN_DEV_PACKAGE = "com.ambulance.project.biz.controller.device";
    public static final String SWAGGER_SCAN_AG_PACKAGE = "com.ambulance.project.biz.controller.agora";
    public static final String SWAGGER_SCAN_TREATWEB_PACKAGE = "com.ambulance.project.biz.controller.treatweb";
    public static final String SWAGGER_SCAN_TREATTER_PACKAGE = "com.ambulance.project.biz.controller.treatter";
    public static final String SWAGGER_SCAN_SOCKET_PACKAGE = "com.ambulance.project.biz.controller.websocket";
    public static final String SWAGGER_SCAN_COMMON_PACKAGE = "com.ambulance.project.biz.controller.common";
    public static final String VERSION = "1.0.0";

//    @Bean
//    public Docket createAdminRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("admin")
//                .apiInfo(new ApiInfoBuilder()
//                        .title("后台管理接口")//设置文档的标题
//                        .description("后台数据管理")//设置文档的描述->1.Overview
//                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
//                        .build())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_ADMIN_PACKAGE))//api接口包扫描路径
//                .paths(PathSelectors.regex(".*/admin/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
//                .build();
//    }
    @Bean
    public Docket createSocketRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .groupName("socket")
            .apiInfo(new ApiInfoBuilder()
                    .title("socket接口-弃用")//设置文档的标题
                    .description("socket管理")//设置文档的描述->1.Overview
                    .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                    .build())
            .select()
            .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_SOCKET_PACKAGE))//api接口包扫描路径
            .paths(PathSelectors.regex(".*/socket/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
            .build();
    }

    @Bean
    public Docket createCommonRestApi() {

        Predicate<String> regex = PathSelectors.regex(".*/common/.*");

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("common")
                .apiInfo(new ApiInfoBuilder()
                        .title("公共接口")//设置文档的标题
                        .description("公共接口管理")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_COMMON_PACKAGE))//api接口包扫描路径
                .paths(regex)//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }

    @Bean
    public Docket createVRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("vr")
                .apiInfo(new ApiInfoBuilder()
                        .title("VR接口")//设置文档的标题
                        .description("VR数据管理")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_VR_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/vr/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }

    @Bean
    public Docket createAgoraRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("agora")
                .apiInfo(new ApiInfoBuilder()
                        .title("声网Agora")//设置文档的标题
                        .description("声网相关接口")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_AG_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/agora/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }



    @Bean
    public Docket createPadRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("pad")
                .apiInfo(new ApiInfoBuilder()
                        .title("随车医生")//设置文档的标题
                        .description("随车医生开发接口实现的文档")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_PAD_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/pad/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
//                .paths(PathSelectors.regex("/logout"))
                .build();
    }



    @Bean
    public Docket createTreatWebtApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("treatweb")
                .apiInfo(new ApiInfoBuilder()
                        .title("会诊子系统web")//设置文档的标题
                        .description("会诊子系统web开发接口实现的文档")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_TREATWEB_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/treat/web/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }



    @Bean
    public Docket createTreatTermtApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("treatter")
                .apiInfo(new ApiInfoBuilder()
                        .title("会诊子系统终端(IOS和安卓)")//设置文档的标题
                        .description("会诊子系统终端开发接口实现的文档")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_TREATTER_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/treat/terminal/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }



    @Bean
    public Docket createWebRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("web")
                .apiInfo(new ApiInfoBuilder()
                        .title("web大屏")//设置文档的标题
                        .description("web大屏开发接口实现的文档")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_WEB_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/web/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }


    @Bean
    public Docket creatDevRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("dev")
                .apiInfo(new ApiInfoBuilder()
                        .title("设备数据")//设置文档的标题
                        .description("设备数据开发接口实现的文档")//设置文档的描述->1.Overview
                        .version(VERSION)//设置文档的版本信息-> 1.1 Version information
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_DEV_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/dev/v1/.*"))//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }
}
